/*
 * table_InitializerDesignation.c
 *
 *  Created on: 2012/03/27
 *      Author: guanxiaoying
 */
#include "../../parser/coredef.h"
#include "../../parser/cc/cc.h"
typedef struct _INITIALIZERDESIGNATION
{
	UCHAR  kind;
	UCHAR bIllegal;
	AST astParam;
	AST astParent;
	AST astChild;
	AST astCodeScp;
	AST astInit;
}INITIALIZERDESIGNATION,*PINITIALIZERDESIGNATION;


#define TableSize  (sizeof(INITIALIZERDESIGNATION))
#define TableType  PINITIALIZERDESIGNATION
#define stTable stInitDesignationManager.memoryBlocks
#define maxTable stInitDesignationManager.maxRecordNum
#define  maxNumPerBlk  (stInitDesignationManager.astMaxNum_Block)

static TABLEMANAGER stInitDesignationManager = {
//		U4                  usIdx;
		0,
//		PSZ				    con_pszName;    constant
		__FILE__,
//		U2					con_usSize;		constant
		TableSize,
//		U2					block_num;	　　　　　　　Reset clear  際　要
		0,
//		S4					astMaxNum_Block;     １回設定のみ
		0,
//		S4					astTabNum_LastPage; 　　　　Reset clear  際　要
		0,
//		S4					astMaxNum_LastPage;     Reset clear  際　要
		0,
//		U4					ulMaxByte;	　　　　　　　　　　クリアしない
		0,
//		U4					con_minPageSize;　　　　　　　　　　constant
		0
};
static VOID resetListener( U4  procid, U2 index )
{
	if( procid == stInitDesignationManager.u4Idx )
	{
		if( index > 0 && index < MAX_VOLUMN_OF_TABLE )
		{
			stTable[ index-1] = NULL;
		}
	}
}
static TableType core_getTable( AST index )
{
	TableType temp = (TableType)Check_Com( &stInitDesignationManager, resetListener, index );
	if( temp != NULL ){ return &temp[index%maxNumPerBlk]; } return NULL;
}


static BOOL ClearTable( VOID )
{
	return Clear_Com( &stInitDesignationManager );
}
static BOOL ResetTable( VOID )
{
	return Reset_Com( &stInitDesignationManager );
}
static BOOL AllocTable( AST astReqArg )
{
	return AllocTable_Com( &stInitDesignationManager, astReqArg, resetListener );
}
static AST getMaxLineNum( VOID ){
	return maxTable;
}
//ACCESS_U2_FIELD   kind;
static U2 getKind( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->kind;
}
static U2 setKind( AST index, U2 value )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->kind = value;
}
//ACCESS_BOOL_FIELD bIllegal;
static BOOL isIllegal( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->bIllegal;
}
static BOOL setIllegal( AST index, BOOL value )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->bIllegal = value;
}
//ACCESS_IDX_FIELD  const_expression;
static AST getConstExp( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	if( pTbl ->kind != DESIGNATION_ARRAY ){
		return 0;
	}
	return pTbl->astParam;
}
static AST setConstExp( AST index, AST value )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	if( pTbl->kind != 0 && pTbl ->kind != DESIGNATION_ARRAY ){
		Throw_MemoryError( &stInitDesignationManager, DATA_SETTING_MISS, index, pTbl->kind );
	}
	pTbl ->kind = DESIGNATION_ARRAY;
	return pTbl->astParam = value;
}
//ACCESS_IDX_FIELD  identifier;
static AST getSym( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	if( pTbl -> kind != DESIGNATION_MEMBER ){
		return 0;
	}
	return pTbl->astParam;
}
static AST setSym( AST index, AST value )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	if( pTbl ->kind == DESIGNATION_ARRAY ){
		Throw_MemoryError( &stInitDesignationManager, DATA_SETTING_MISS, index, pTbl->kind );
	}
	pTbl ->kind = DESIGNATION_MEMBER;
	return pTbl->astParam = value;
}
//ACCESS_IDX_FIELD  token;
static AST getToken( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	if( pTbl -> kind != DESIGNATION_TOKEN ){
		return 0;
	}
	return pTbl->astParam;
}
static AST setToken( AST index, AST value )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	if( pTbl ->kind == DESIGNATION_ARRAY ){
		Throw_MemoryError( &stInitDesignationManager, DATA_SETTING_MISS, index, pTbl->kind );
	}
	pTbl ->kind = DESIGNATION_TOKEN;
	return pTbl->astParam = value;
}
//ACCESS_IDX_FIELD  parent;
static AST getParent( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astParent;
}
static AST setParent( AST index, AST idx )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astParent = idx;
}
//ACCESS_IDX_FIELD  child;
static AST getChild( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astChild;
}
static AST setChild( AST index, AST idx )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astChild = idx;
}
//ACCESS_IDX_FIELD  codeScp;
static AST getLoc( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astCodeScp;
}
static AST setLoc( AST index, AST idx )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astCodeScp = idx;
}
//ACCESS_IDX_FIELD  initializer;
static AST getInit( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astInit;
}
static AST setInit( AST index, AST idx )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astInit = idx;
}


const INITIALIZERDESIGNATIONACCESS stInitDesignationAccess={

				ClearTable,
				ResetTable,
				AllocTable,
				getMaxLineNum,

		{
				getKind,
				setKind
		},
		{
				isIllegal,
				setIllegal
		},
		{
				getConstExp,
				setConstExp
		},
		{
				getSym,
				setSym
		},
		{
				getToken,
				setToken
		},
		{
				getParent,
				setParent
		},
		{
				getChild,
				setChild
		},
		{
				getLoc,
				setLoc
		},
		{
				getInit,
				setInit
		}
};
